package com.example.demo.controller.userInfo;

import java.util.List;

import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.example.demo.controller.BaseController;
import com.example.demo.domain.menu.Menu;
import com.example.demo.domain.userInfo.UserInfo;
import com.example.demo.service.menu.MenuService;
import com.example.demo.service.userInfo.UserInfoService;

@Controller
public class IndexController extends BaseController {
	@Autowired
	private MenuService menuService;
	
	@Autowired
	private UserInfoService userService;

	@GetMapping("/index")
	public String index(ModelMap mmap) {
		// 取身份信息
		UserInfo user = (UserInfo) SecurityUtils.getSubject().getPrincipal();
		// 根据用户id取出菜单
		mmap.put("user", user);
		return "index";
	}
	
	@RequestMapping("/selectMenuByUser")
	@ResponseBody
	public List<Menu> menu(Integer uid){
		
		UserInfo user = userService.selectByPrimaryKey(uid);
		List<Menu> menus = menuService.selectMenusByUser(user);
		return menus;
		
	}
	
	

}
